Let's inspect and visualize the input to our strategy and its results.
import pandas as pd
import json
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
quotes = pd.read_json("quotes.json")
with open("order-depths.json", "r") as fp:
depths = json.load(fp)
depth = [int(k) for k in depths.keys()]
counts = depths.values()
d= {"depth_cents": depth, "count": counts}
depth_df = pd.DataFrame(d)
depth_df.head()
| depth_cents | count | |
|---|---|---|
| 0 | 0 | 221 |
| 1 | 155 | 1 |
| 2 | -155 | 2 |
| 3 | -98 | 1 |
| 4 | 29 | 1 |
px.histogram(depth_df, x="depth_cents", y="count")
We decide to place our bid and asks as these distances from the best ask and bid.
depth_df["depth_cents"].quantile(0.25)
-100.0
depth_df["depth_cents"].quantile(0.75)
52.75
This is what happened uring the simulation.
quotes
| time | best_bid | best_ask | my_bid | my_ask | filled_asks | filled_bids | |
|---|---|---|---|---|---|---|---|
| 0 | 1.643832e+09 | 37614.99 | 37615.00 | 37613.99 | 37615.53 | 0 | 0 |
| 1 | 1.643832e+09 | 37602.80 | 37602.81 | 37601.80 | 37603.34 | 0 | 1 |
| 2 | 1.643832e+09 | 37605.99 | 37606.00 | 37604.99 | 37606.53 | 1 | 0 |
| 3 | 1.643832e+09 | 37579.58 | 37579.59 | 37578.58 | 37580.12 | 0 | 1 |
| 4 | 1.643832e+09 | 37579.58 | 37579.59 | 37578.58 | 37580.12 | 1 | 0 |
| 5 | 1.643832e+09 | 37552.76 | 37552.77 | 37551.76 | 37553.30 | 0 | 1 |
| 6 | 1.643832e+09 | 37551.02 | 37551.03 | 37550.02 | 37551.56 | 1 | 1 |
| 7 | 1.643832e+09 | 37567.43 | 37567.93 | 37566.43 | 37568.46 | 1 | 1 |
| 8 | 1.643832e+09 | 37573.00 | 37573.01 | 37572.00 | 37573.54 | 1 | 1 |
| 9 | 1.643832e+09 | 37590.77 | 37590.78 | 37589.77 | 37591.31 | 1 | 0 |
| 10 | 1.643832e+09 | 37594.74 | 37594.75 | 37593.74 | 37595.28 | 1 | 1 |
| 11 | 1.643832e+09 | 37591.43 | 37591.44 | 37590.43 | 37591.97 | 1 | 1 |
| 12 | 1.643832e+09 | 37584.00 | 37584.01 | 37583.00 | 37584.54 | 1 | 1 |
| 13 | 1.643832e+09 | 37577.97 | 37577.98 | 37576.97 | 37578.51 | 0 | 1 |
| 14 | 1.643832e+09 | 37588.36 | 37590.80 | 37587.36 | 37591.33 | 1 | 0 |
| 15 | 1.643832e+09 | 37600.71 | 37600.72 | 37599.71 | 37601.25 | 1 | 1 |
| 16 | 1.643832e+09 | 37602.44 | 37602.45 | 37601.44 | 37602.98 | 1 | 1 |
All filled orders are marked as dots on the plot.
quotes["time_rel"] = quotes["time"] - quotes["time"][0]
fig1 = px.line(quotes, x="time_rel", y=["best_ask","best_bid","my_ask","my_bid"])
fig2 = px.scatter(quotes[quotes["filled_asks"] == 1], x="time_rel", y="my_ask")
fig3 = px.scatter(quotes[quotes["filled_bids"] == 1], x="time_rel", y="my_bid")
fig4 = go.Figure(data=fig1.data + fig2.data + fig3.data)
fig4.show()
quotes["filled_asks"].mean()
0.7058823529411765
quotes["filled_bids"].mean()
0.7058823529411765